package com.dhsc.service.impl.ywjk.jzcl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.jkzx.ywjk.jzcl.YcmxlsVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.domain.yypt.yhzx.TJgxxVo;
import com.dhsc.domain.yypt.yhzx.TYhxxVo;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.ywjk.jzcl.IYcmxDao;
import com.dhsc.local.dao.yypt.IYhzxDao;
import com.dhsc.service.ywjk.jzcl.IYcmxService;
import com.dhsc.util.CommonUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: YcmxlsServiceImpl
 * @Description: 当前异常明细
 * @date: 2023/8/29 14:54
 * @author: gx
 */
@Service
@Slf4j
public class YcmxServiceImpl implements IYcmxService {

    @Autowired
    private IYcmxDao ycmxlsDao;

	@Autowired
	private IYhzxDao yhzxDao;

    @Override
    public LayuiTableVo queryYcmx(YcmxlsVo ycmxlsVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try{
            PageMethod.startPage(ycmxlsVo.getPage(), ycmxlsVo.getLimit());
            List<YcmxlsVo> list = ycmxlsDao.queryYcmx(ycmxlsVo);
            PageInfo<YcmxlsVo> pageInfo = new PageInfo<>(list);
            
            if(CommonUtil.isNotEmptyList(list))
			{
				List<TYhxxVo> yhlist = yhzxDao.queryTYhxx(new TYhxxVo());
				List<TJgxxVo> jglist = yhzxDao.queryTJgxx(new TJgxxVo());
				
				for(int i = 0;i < list.size();i ++)
				{
					for(int j = 0;j < yhlist.size();j ++)
					{
						if(list.get(i).getUserid() == yhlist.get(j).getUserid())
						{
							list.get(i).setCzgy_name(yhlist.get(j).getTruename());
						}
					}
					for(int j = 0;j < jglist.size();j ++)
					{
						if(list.get(i).getYyb().equals(jglist.get(j).getJgdm()))
						{
							list.get(i).setYybmc(jglist.get(j).getBmmc());
						}
						if(list.get(i).getFsyyb().equals(jglist.get(j).getJgdm()))
						{
							list.get(i).setFsyybmc(jglist.get(j).getBmmc());
						}
					}
				}
			}
            
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch(Exception e){
            log.error("查询当前异常明细信息出错", e);
            throw new MyException("查询当前异常明细信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject saveYcmx(YcmxlsVo ycmxlsVo) {
        ResponseObject obj = new ResponseObject();
        try{
            ycmxlsDao.updateYcmx(ycmxlsVo);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("保存当前异常明细信息出错", e);
            throw new MyException("保存当前异常明细信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryClr() {
        ResponseObject obj = new ResponseObject();
        try{
            List<YcmxlsVo> list = ycmxlsDao.queryClr();
            obj.setData(list);
            obj.setStatus(200);
        }catch(Exception e){
            log.error("查询处理人信息出错", e);
            throw new MyException("查询处理人信息出错",e);
        }
        return obj;
    }

}
